package com.example.kehoobackend.controller;


import com.example.kehoobackend.common.CommonResponse;
import com.example.kehoobackend.service.AnswerService;
import com.example.kehoobackend.service.FollowService;
import com.example.kehoobackend.service.QuestionService;
import com.example.kehoobackend.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

@Validated
@CrossOrigin
@RestController
public class UnionController {

    @Autowired
    private FollowService followService;

    @Autowired
    private QuestionService questionService;

    @Autowired
    private AnswerService answerService;


    /**
     * union_001
     *
     * @param question_id 问题id
     * @param user_id 用户id
     * @return CommonResponse<List<Boolean>>
     */
    @GetMapping("/union/001")
    public CommonResponse<List<Boolean>> union_001(
            @RequestParam("question_id") Integer question_id,
            @RequestParam("user_id") Integer user_id) {

        ArrayList<Boolean> tempList = new ArrayList<>();
        tempList.add(followService.isFollow(user_id,question_id,1));
        tempList.add(questionService.isLike(question_id,user_id));
        Integer id = questionService.getUserIdByQuestionId(question_id);
        tempList.add(followService.isFollow(user_id, id,0));
        return CommonResponse.createForSuccess("联合查询结果", tempList);
    }

}
